﻿<script type="text/javascript">

    var TimingService = {};
    TimingService.delTimingUrl = "";
    TimingService.TimingFlowUrl = "";
    TimingService.editTimingUrl = "";

    TimingService.DeleteFormatter = function (value, rec, index) {
        if (rec.StateID == 1)
            return "";
        return "<a  class='btn-del' href='" + TimingService.delTimingUrl + "/" + rec.UID + "' onclick='Delete(this); return false;' >删除</a>";
    }

    TimingService.EditFormatter = function (value, rec, index) {
        return "<a  class='btn-edit' href='" + $("#editTimingUrl").val() + "/" + rec.UID + "' onclick='Edit(this); return false;' >修改</a>";
    }

    TimingService.TimingFlowFormatter = function (value, rec, index) {
        return "<a  class='btn-list' href='" + TimingService.TimingFlowUrl + "/" + rec.UID + "' onclick='TimingService.ShowFlowList(this); return false;' >查看</a>";
    }

    TimingService.TimingLogFormatter = function (value, rec, index) {
        return "<a  class='btn-view' href='" + $("#logTimingUrl").val() + "/" + rec.UID + "' onclick='TimingService.ShowLogList(this); return false;' >查看</a>";
    }

    TimingService.TimingRunNowFormatter = function (value, rec, index) {
        return "<a  class='btn-refresh' href='" + $("#runNowTimingUrl").val() + "/" + rec.UID + "' onclick='TimingService.RunNow(this); return false;' >立即运行当前服务</a>";
    }

    TimingService.StateFormatter = function (value, rec, index) {
        return value == 1 ? "启用" : "禁用";
    }

    TimingService.PriorityFormatter = function (value, rec, index) {
        var prioritys = ["最低", "低于普通", "普通", "高于普通", "最高"];
        return prioritys[parseInt(value)];
    }

    TimingService.ShowFlowList = function (e) {
        Common.ShowTab(e, $(e).parents("tr").find("td:first").text());
    }


    TimingService.ShowLogList = function (e) {
        Common.ShowTab(e, $(e).parents("tr").find("td:first").text() + "日志");
    }


    TimingService.RunNow = function (e) {
        if (!confirm("确认要立即运行当前服务吗？"))
            return;
        $.post($(e).attr("href"), function (data) {
            alert(data.Description);
        });
    }

    function Delete(e) {
        if (!confirm("确认要删除吗？"))
            return;
        $.post($(e).attr("href"), function (data) {
            if (data.IsOK) {
                $('#tbTimingList').datagrid('reload');
            }
            else
                alert(data.Description);
        });
    }

    function Edit(e) {
        $.createWin({ url: e.href, width: 600, height: 550, title: '修改定时服务' });
        return false;
    }

    function TimingFlow(e) {
        Common.ShowTab(e, $(e).parents("tr").find("td:first").text());
    }

    $(document).ready(function () {
        TimingService.delTimingUrl = $("#delTimingUrl").val();
        TimingService.TimingFlowUrl = $("#detailTimingUrl").val();
        TimingService.ModifyUrl = $("#serviceeditTimingUrl").val();
        $('#tbTimingList').datagrid({ pagination: true });

        // 搜索按钮事件
        $("#btnTimingSearch").unbind("click");
        $("#btnTimingSearch").click(function () {
            $('#tbTimingList').datagrid({ pageNumber: 1, queryParams: { SearchWord: $("#txtTimingSearchWord").val()} });
        });
    });

</script>
@Html.Hidden("detailTimingUrl", Url.Action("FlowList"))
@Html.Hidden("delTimingUrl", Url.Action("Delete"))
@Html.Hidden("editTimingUrl", Url.Action("Edit"))
@Html.Hidden("logTimingUrl", Url.Action("LogList"))
@Html.Hidden("runNowTimingUrl", Url.Action("RunNow"))
<div class="tt-attach">
    <ul class="op">
        <li>
            <input class="search-text" id="txtTimingSearchWord" style="width: 100px;"
                title="请输入关键字进行搜索" type="text" value=""><input id="btnTimingSearch" class="search-button" value="搜索" type="button">
        </li>
    </ul>
</div>
<div style="padding: 5px 10px;">
    <table id="tbTimingList" style="height: auto" striped="true" rownumbers="true" nowrap="false" fitColumns="true" title="" iconcls="icon-edit"
    singleselect="true" idfield="UID" url="@Url.Action("ListData")">
        <thead>
            <tr>
                <th field="ServiceName" width="150">
                    服务名称
                </th>
                <th field="AttemperDesc" width="350">
                    调度描述
                </th>
                <th field="StateCodeID" formatter="TimingService.StateFormatter" width="50" align="center">
                    调度状态
                </th>
                <th field="流程" width="50" formatter="TimingService.TimingFlowFormatter" align="center">
                    流程
                </th>
                <th field="日志" width="50" formatter="TimingService.TimingLogFormatter" align="center">
                    日志
                </th>
                <th field="立即运行" width="50" formatter="TimingService.TimingRunNowFormatter" align="center">
                    运行
                </th>
                <th field="修改" width="50" formatter="TimingService.EditFormatter" align="center">
                    修改
                </th>
                <th field="删除" width="50" formatter="TimingService.DeleteFormatter" align="center">
                    删除
                </th>
            </tr>
        </thead>
    </table>
</div>
